package org.luckystrophe.snowtoms.manager;

import java.security.MessageDigest;

import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.api.Scope;

@EBean(scope = Scope.Singleton)
public class Md5Maker {

	private static String md5Key = "mas2@SEOUL@";

	public static String encryptString(String keyWord, long timeStamp) {
		StringBuffer beforeMd5 = new StringBuffer();

		MessageDigest md5 = null;
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (Exception e) {
			e.printStackTrace();
		}
		beforeMd5.append(keyWord).append(timeStamp).append(md5Key);
		md5.update(beforeMd5.toString().getBytes());

		byte[] convertBeforeMd5 = md5.digest();
		int converBeforeMd5Length = convertBeforeMd5.length;

		StringBuffer afterMd5 = new StringBuffer();

		for (int i = 0; i < converBeforeMd5Length; i++) {
			String ch = String.format("%02x", 0xff & (char) convertBeforeMd5[i]);
			afterMd5.append(ch);
		}
		return afterMd5.toString();
	}
}
